'use strict';
app.factory('adminService',function($http, $location,loginService){
	return{
		delete_admin:function(username,password,userid){
			var $promise=$http.get(loginService.getLink()+'admin/del/'+username+'/'+password+'/'+userid); 
				
			$promise.success(function(msg) {
			   $location.path('/admin_');
			 				   
			});
			$promise.error(function(data, status, headers, config) {
	            	alert('can not delete admin');
	          	 });	
		},
		
	    delete_interest:function(username,password,interest){
			var $promise=$http.get(loginService.getLink()+'interest_/del/'+username+'/'+password+'/'+interest); 
			$promise.success(function(msg) {
			   $location.path('/interest_');
			});
			$promise.error(function(data, status, headers, config) {
	            	alert('can not delete interest');
	          	});	
		},
		
		submit_admin:function(username,password,firstname,lastname,id,status,role){
			var $promise=$http.get(loginService.getLink()+'admin/update/'+username+'/'+ password+'/'+firstname+'/'+lastname+'/'+id+'/'+status+'/'+role ); 
				
			$promise.success(function(msg) {
			   $location.path('/admin');
			   var uid=msg.data;
				if(uid){ 
				   $location.path('/admin');
				}	       
				else{
					//scope.msgtxt='incorrect information';
					$location.path('/admin');
				}				   
			});
			$promise.error(function(data, status, headers, config) {
	            	alert('can not update admin');
	          	   
	            });	
		},
		
			submit_interest:function(username,password,interest,id){
		    if(id==0)
			  var $promise=$http.get(loginService.getLink()+'interest_/update/'+username+'/'+ password+'/'+interest+'/0'); 
			else
			  var $promise=$http.get(loginService.getLink()+'interest_/update/'+username+'/'+ password+'/'+interest+'/'+id); 
			
			$promise.success(function(msg) {
			  if(msg.error_no==0)
			     $location.path('/interest');
			  else{
				 alert('interest exist, please add other one'); 
			  }
			  // var uid=msg.data;
				//if(uid){ 
				  // $location.path('/interest');
				//}	       
				//else{
					//scope.msgtxt='incorrect information';
					//$location.path('/interest');
				//}				   
			});
			$promise.error(function(data, status, headers, config) {
	            	alert('can not update interest,problem of connection ');
	          	 });	
		},
		
		
	
	}

});